package com.seuic.hnjiningposapp.hnapps.ui.view.dialog;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.ToastUtils;
import com.lxj.xpopup.core.BasePopupView;
import com.lxj.xpopup.core.CenterPopupView;
import com.seuic.hnjiningposapp.R;
import com.seuic.hnjiningposapp.hnapps.ui.view.CEditText;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

public class InputPasswordPopup extends CenterPopupView {//输入密码弹窗
    Context context;
    Activity activity;
    Unbinder bind;
    ClickCallback callevent;
    @BindView(R.id.tv_password_title)
    TextView tvPasswordTitle;//输入提示
    @BindView(R.id.edit_inputpassword)
    CEditText editInputpassword;//密码
    @BindView(R.id.import_password_gz)
    Button importPasswordGz;//更正
    @BindView(R.id.import_password_ok)
    Button importPasswordOk;//确认
    @BindView(R.id.import_password_layout)
    LinearLayout importPasswordLayout;

    String title = "请输入您的密码";

    public InputPasswordPopup(@NonNull Context context,  ClickCallback callevent) {
        super(context);
        this.context = context;
        this.callevent = callevent;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public interface ClickCallback {
        void SendPassword(String password);
    }



    @Override
    protected int getImplLayoutId() {
        return  R.layout.dialog_inputpassword;
    }

    @Override
    protected void onCreate() {
        super.onCreate();
        bind = ButterKnife.bind(this);
        tvPasswordTitle.setText(title);
    }

    @OnClick({R.id.import_password_gz, R.id.import_password_ok})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.import_password_gz:
                editInputpassword.setText("");
                break;
            case R.id.import_password_ok:
                if (editInputpassword.getText().toString().equals("")) {
                    ToastUtils.showLong("请输入密码");
                } else {
                    callevent.SendPassword(editInputpassword.getText().toString());
                }
                break;
        }
    }

    protected void onShow() {
        super.onShow();
    }

    @Override
    protected void onDismiss() {
        super.onDismiss();
        //注解解绑
        if (bind != null && bind != Unbinder.EMPTY) {
            bind.unbind();
        }
        this.bind = null;
    }
}